import HouseReportBusiness from '@/business/HouseReportBusiness';
import reportStore from '@/stores/ReportStore';
import { useMemo } from 'react';
import BusinessConstant from '@/constant/BusinessConstant';

export default function useReport() {
  const {landlordReportList, setTenantReportList, setLandlordReportList} = reportStore;

  /**
   * 通过租客id获取该租客的全部房屋维修信息
   * @param tenantId
   */
  const getReportByTenantId = async (tenantId: number) => {
    if (!tenantId) return;
    const res: any = await HouseReportBusiness.getReportByTenantId(tenantId);
    setTenantReportList(res);
  };

  /**
   * 获取房东的房屋报修（租客的报修记录）
   * @param landlordId
   */
  const getReportByLandlordId = async (landlordId: number) => {
    if (!landlordId) return;
    const res: any = await HouseReportBusiness.getReportByLandlordId(landlordId);
    setLandlordReportList(res);
  };

  /**
   * 房东房屋维修列表待处理数量
   */
  const landlordReportPendingNoticeNum = useMemo(
    () => landlordReportList?.filter(l => l.status === BusinessConstant.REPORT_PENDING).length,
    [landlordReportList]
  );

  return {
    getReportByTenantId,
    getReportByLandlordId,
    landlordReportPendingNoticeNum,
  };
}